package logic

import (
	"context"
	"gorm.io/gorm"
	"product/model/mysql"

	"product/productrpc/internal/svc"
	"product/productrpc/productrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductUpdateLogic {
	return &ProductUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 用户详情
func (l *ProductUpdateLogic) ProductUpdate(in *productrpc.ProductUpdateRequest) (*productrpc.ProductUpdateResponse, error) {
	// todo: add your logic here and delete this line

	products := mysql.Products{
		Model:        gorm.Model{ID: uint(in.ProductId)},
		UserId:       in.UserId,
		Title:        in.Title,
		Price:        float64(in.Price),
		BrowseNumber: in.BrowseNumber,
		Image:        in.Image,
		ClassId:      in.ClassId,
	}
	mysql.DB.Debug().Where("id=?", in.ProductId).Updates(&products)
	return &productrpc.ProductUpdateResponse{
		Id: int64(products.ID),
	}, nil
}
